package com.zkca.xf.utils;

import java.util.Collection;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Twilight on 2015/1/19.
 */
public final class ValidateUtils {
    /**
     * 手机号验证
     *
     * @param str
     * @return 验证通过返回true
     */
    public static boolean isMobile(String str) {
        if (!validateString(str))
            return false;
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1][3,4,5,8,7][0-9]{9}$"); // 验证手机号
        m = p.matcher(str);
        b = m.matches();
        return b;
    }

    public static boolean validateString(String... text) {
        for (int i = 0; i < text.length; i++) {
            if (text[i] == null || "".equals(text[i])) {
                return false;
            }
        }
        return true;
    }

    public static boolean validateConnection(Collection<?> collection) {
        if (collection == null || collection.size() <= 0) {
            return false;
        }
        return true;
    }

    public static boolean validateMap(Map<?, ?> map) {
        if (map == null || map.size() <= 0) {
            return false;
        }
        return true;
    }

    public static boolean isEmpty(Map<?, ?> map) {
        if (map == null) {
            return false;
        }
        return true;
    }
}
